home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS02.ADF / IFF / raw2ilbm.c < prev    next >
Text File  |  1989-05-30  |  3KB  |  85 lines

  1. /** Raw2ILBM.c **************************************************************
  2.  *
  3.  * Read an raw raster image file and write an IFF FORM ILBM file.  11/15/85.
  4.  *
  5.  * By Jerry Morrison and Steve Shaw, Electronic Arts.
  6.  * This software is in the public domain.
  7.  *
  8.  * USE THIS AS AN EXAMPLE PROGRAM FOR AN IFF WRITER.
  9.  *
  10.  ****************************************************************************/
  11. #include "graphics/system.h"
  12. #include "iff/ilbm.h"
  13.  
  14. /* Size of the buffer for PutBODY. */
  15. #define bufSize 512
  16.  
  17.  
  18. /** PutAnILBM() *************************************************************
  19.  *
  20.  * Write an entire BitMap as a FORM ILBM in an IFF file.
  21.  * This procedure assumes the image is in the Amiga's 320 x 200 display mode.
  22.  *
  23.  * Normal return result is IFF_OKAY.
  24.  *
  25.  * The utility program IFFCheck would print the following outline of the
  26.  * resulting file:
  27.  *
  28.  *   FORM ILBM
  29.  *     BMHD
  30.  *     CMAP
  31.  *     BODY       (compressed)
  32.  *
  33.  ****************************************************************************/
  34. #define CkErr(expression)  {if (ifferr == IFF_OKAY) ifferr = (expression);}
  35.  
  36. IFFP PutAnILBM(file, bitmap, mask, colorMap, depth, xy, buffer, bufsize)
  37.       LONG file;  struct BitMap *bitmap;  BYTE *mask;  WORD *colorMap;
  38.       UBYTE depth;  Point2D *xy;  BYTE *buffer;  LONG bufsize;
  39.    {
  40.    BitMapHeader bmHdr;
  41.    GroupContext fileContext, formContext;
  42.    IFFP ifferr;
  43.  
  44.    ifferr = InitBMHdr(&bmHdr, bitmap, mskNone, cmpByteRun1, 0, 320, 200);
  45.     /* You could write an uncompressed image by passing cmpNone instead
  46.      * of cmpByteRun1 to InitBMHdr. */
  47.    bmHdr.nPlanes = depth;    /* This must be  <= bitmap->Depth */
  48.    if (mask != NULL) bmHdr.masking = mskHasMask;
  49.    bmHdr.x = xy->x;   bmHdr.y = xy->y;
  50.  
  51.    CkErr( OpenWIFF(file, &fileContext, szNotYetKnown) );
  52.    CkErr(StartWGroup(&fileContext, FORM, szNotYetKnown, ID_ILBM, &formContext));
  53.  
  54.    CkErr( PutBMHD(&formContext, &bmHdr) );
  55.    CkErr( PutCMAP(&formContext, colorMap, depth) );
  56.    CkErr( PutBODY(&formContext, bitmap, mask, &bmHdr, buffer, bufsize) );
  57.  
  58.    CkErr( EndWGroup(&formContext) );
  59.    CkErr( CloseWGroup(&fileContext) );
  60.    return( ifferr );
  61.    }    
  62.  
  63. /** PutPicture() ************************************************************
  64.  *
  65.  * Put a picture into an IFF file.
  66.  * This procedure calls PutAnILBM, passing in an <x, y> location of <0, 0>,
  67.  * a NULL mask, and a locally-allocated buffer. It also assumes you want to
  68.  * write out all the bitplanes in the BitMap.
  69.  *
  70.  ****************************************************************************/
  71. Point2D nullPoint = {0, 0};
  72.  
  73. IFFP PutPicture(file, bitmap, colorMap)
  74.       LONG file;  struct BitMap *bitmap;  WORD *colorMap;
  75.    {
  76.    BYTE buffer[bufSize];
  77.    return( PutAnILBM(file, bitmap, NULL,
  78.              colorMap, bitmap->Depth, &nullPoint,
  79.              buffer, bufSize) );
  80.    }    
  81.  
  82. /* [TBD] More to come. We need code to read a "raw" raster file into a BitMap
  83.  * and code to handle file opening & closing, error msgs, etc. */
  84.  
  85.